package com.luying.controller.controller;

import com.luying.constants.RoleTypeEnum;
import com.luying.pojo.*;
import com.luying.pojo.Class;
import com.luying.service.BasicInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 基本信息维护controller
 */
@RestController
@RequestMapping("/basic")
public class BasicInfoController {

    @Autowired
    private BasicInfoService basicInfoService;

    @PostMapping("/class/add")
    public Result addClass(@RequestBody Class aClass) {
        try {
            return Result.ok(basicInfoService.addClass(aClass));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/class/query")
    public Result queryClass(@RequestBody PageQuery pageQuery) {
        return Result.ok(basicInfoService.queryClass(pageQuery));
    }

    @GetMapping("/class/delete")
    public Result deleteClass(@RequestParam(name = "id") Integer id) {
        try {
            return Result.ok(basicInfoService.deleteClass(id));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/class/update")
    public Result updateClass(@RequestBody Class aclass) {
        return Result.ok(basicInfoService.updateClass(aclass));
    }

    @PostMapping("/subject/add")
    public Result addSubject(@RequestBody Subject subject) {
        return Result.ok(basicInfoService.addSubject(subject));
    }

    @PostMapping("/subject/query")
    public Result querySubject(@RequestBody PageQuery pageQuery) {
        return Result.ok(basicInfoService.querySubject(pageQuery));
    }

    @GetMapping("/subject/delete")
    public Result deleteSubject(@RequestParam(name = "id") Integer id) {
        try {
            return Result.ok(basicInfoService.deleteSubject(id));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    @PostMapping("/subject/update")
    public Result updateSubject(@RequestBody Subject subject) {
        return Result.ok(basicInfoService.updateSubject(subject));
    }

    @PostMapping("/classAndSubject/update")
    public Result updateClassAndSubject(@RequestBody ClassAndSubjectVo classAndSubject) {
        basicInfoService.updateClassAndSubject(classAndSubject);
        return Result.ok();
    }

    /**
     * 班级和科目list
     *
     * @return
     */
    @GetMapping("/classAndSubject/list")
    public Result classAndSubjectList() {
        return Result.ok(basicInfoService.classAndSubjectList());
    }

    /**
     * 班级和科目关系列表
     *
     * @return
     */
    @PostMapping("/classAndSubject/query")
    public Result classAndSubjectQuery(@RequestBody PageQuery query) {
        return Result.ok(basicInfoService.classAndSubjectQuery(query));
    }

    @PostMapping("/moral/add")
    public Result addMoral(@RequestBody Moral moral) {
        return Result.ok(basicInfoService.addMoral(moral));
    }

    @PostMapping("/moral/query")
    public Result queryMoral(@RequestBody PageQuery pageQuery) {
        return Result.ok(basicInfoService.queryMoral(pageQuery));
    }

    @GetMapping("/moral/delete")
    public Result deleteMoral(@RequestParam(name = "id") Integer id) {
        return Result.ok(basicInfoService.deleteMoral(id));
    }

    @PostMapping("/moral/update")
    public Result updateMoral(@RequestBody Moral moral) {
        return Result.ok(basicInfoService.updateMoral(moral));
    }
}
